package com.papercutting.platform.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.papercutting.platform.entity.UserLike;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户点赞数据访问接口
 */
@Mapper
public interface UserLikeRepository extends BaseMapper<UserLike> {
    
    /**
     * 查找已删除的点赞记录（忽略逻辑删除标记）
     */
    @Select("SELECT * FROM pc_user_like WHERE user_id = #{userId} AND target_type = #{targetType} AND target_id = #{targetId} AND deleted = 1 LIMIT 1")
    UserLike findDeletedRecord(@Param("userId") Long userId, @Param("targetType") String targetType, @Param("targetId") Long targetId);
    
    /**
     * 恢复已删除的记录（忽略逻辑删除标记）
     */
    @Update("UPDATE pc_user_like SET deleted = 0, update_time = NOW() WHERE id = #{id}")
    int restoreRecord(@Param("id") Long id);
    
    /**
     * 软删除记录（忽略逻辑删除标记）
     */
    @Update("UPDATE pc_user_like SET deleted = 1, update_time = NOW() WHERE id = #{id}")
    int softDeleteRecord(@Param("id") Long id);
    
    /**
     * 查询所有相关记录（包括已删除的）- 忽略逻辑删除标记
     */
    @Select("SELECT * FROM pc_user_like WHERE user_id = #{userId} AND target_type = #{targetType} AND target_id = #{targetId}")
    java.util.List<UserLike> findAllRecords(@Param("userId") Long userId, @Param("targetType") String targetType, @Param("targetId") Long targetId);
}